#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <utility>
using namespace std;

#define mm(a, n) memset(a, n, sizeof a)
#define mk(a, b) make_pair(a, b)

const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;

inline void quickread(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

string low[13] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
string high[13] = {"tret", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};

inline void solution(){
    int n;
    string s;
    scanf("%d\n", &n);
    while (n -- ) {
        getline(cin, s);
        if (isdigit(s[0])) {
            int n = stoi(s);
            if (n % 13 != 0 && n > 13) {
                printf("%s %s\n", high[n / 13].c_str(), low[n % 13].c_str());
            } else {
                if (n < 13)
                    printf("%s\n", low[n].c_str());
                else
                    printf("%s\n", high[n / 13].c_str());
            }
        } else {
            if (s.size() == 7) {
                int h, l;
                for (int i = 1; i <= 12; i ++ ) {
                    if (high[i] == s.substr(0, 3)) {
                        h = i; break;
                    }
                }
                for (int i = 0; i <= 12; i ++ ) {
                    if (low[i] == s.substr(4)) {
                        l = i; break;
                    }
                }
                printf("%d\n", h * 13 + l);
            } else {
                for (int i = 1; i <= 12; i ++ ) 
                    if (high[i] == s) {
                        printf("%d\n", i * 13);
                    }
                for (int i = 0; i <= 12; i ++ ) 
                    if (low[i] == s) {
                        printf("%d\n", i);
                    }
            }
        }
    }
}

int main()
{
    freopen("input.txt", "r", stdin);
    // quickread();
    solution();
    return 0;
}